package com.pdsu.graduation_design.views;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.pdsu.graduation_design.R;
import com.pdsu.graduation_design.adapter.MyAddressListViewAdapter;
import com.pdsu.graduation_design.domain.UserAddress;

import java.util.ArrayList;
import java.util.List;
import java.util.zip.Inflater;

public class My_Address_Activity extends AppCompatActivity {

    private ListView addressList;
    private Context context;
    private List<UserAddress> userAddresses;
    private View v;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        //假数据
        userAddresses=new ArrayList<>();
        userAddresses.add(new UserAddress(1,"xpf","15225200001","河南1",true));
        userAddresses.add(new UserAddress(2,"xpf2","15225200002","河南2",false));
        userAddresses.add(new UserAddress(3,"xpf3","15225200003","河南3",false));


        System.out.println(userAddresses.size()+"----------------");
        super.onCreate(savedInstanceState);
        if (userAddresses.size()==0){
          v =View.inflate(getApplicationContext(),R.layout.my_empty_commonly,null);
            TextView t= v.findViewById(R.id.empty_common_top_title);
            t.setText("地址列表");
            setContentView(v);

        }else {
            System.out.println(">0");
            setContentView(R.layout.activity_my_address);
            init();
            bind();
        }



    }

    void init(){
        context=getApplicationContext();
        System.out.println("初始化----------------");
        addressList=findViewById(R.id.my_address_lv);
    }
    void bind(){
        System.out.println("绑定----------------");

        addressList.setAdapter(new MyAddressListViewAdapter(context,userAddresses));
        addressList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                System.out.println(position);
            }
        });

    }
}